class Model
	def initialize
		@figurArray = Array.new
	end
	def nyFigur(figur)
		@figurArray << figur
	end
	def getFigur(num)
		@figurArray[num]
	end
	def getAntalFigurer
		@figurArray.length
	end
end

$model = Model.new

class Led
	attr_reader :del, :opx, :opy, :nedx, :nedy
	attr_writer :del, :opx, :opy, :nedx, :nedy
end

class SPunkt
	attr_reader :del, :x, :y
	attr_writer :del, :x, :y
end

class Del
	attr_reader :billede, :rotation, :skjult, :led, :spunkter
	attr_writer :billede, :rotation, :skjult, :led, :spunkter
	def initialize
		@led = Hash.new
	end
	def move
		for i in 0...self.led.length
			self.led.values[i].del.move
		end
	end
	def Drej (rot, fart)
		if(self.rotation > rot)
			self.rotation -= fart
			if (self.rotation < rot)
				self.rotation = rot
			end
		else
			self.rotation += fart
			if (self.rotation > rot)
				self.rotation = rot
			end
		end
		(self.rotation == rot)
	end
end

class Figur < Del
	attr_reader :x, :y, :centerx, :centery, :navn
	attr_writer :x, :y, :centerx, :centery, :navn
	def initialize(navn)
		super()
		@navn = navn
		$model.nyFigur(self)
	end
end

class HBen < Del
	def initialize
		super
		@retning = true
		self.rotation = 0
		self.billede="hben"
	end
	
	def move
		super
		if @retning == true
			self.rotation -= 1
			if self.rotation < -10
				@retning = false
			end
		elsif @retning == false
			self.rotation += 1
			if self.rotation > 10
				@retning = true
			end
		end
	end
end

class VBen < Del
	def initialize
		super
		@retning = true
		self.rotation = 0
		self.billede="vben"
	end
	
	def move
		super
		if @retning == true
			self.rotation -= 1
			if self.rotation < -10
				@retning = false
			end
		elsif @retning == false
			self.rotation += 1
			if self.rotation > 10
				@retning = true
			end
		end
	end
end

class HArm < Del
	def initialize
		super
		self.rotation = 0
		self.billede="harm"
	end
end

class VArm < Del
	def initialize
		super
		self.rotation = 0
		self.billede="varm"
	end
end

class Hoved < Del
	def initialize
		super
		self.rotation = 0
		self.billede = "hoved"
	end
end	

class Mand < Figur
	def initialize(navn)
		super(navn)
		self.x=150
		self.y=150
		self.billede="krop"
		self.rotation=0
		
		#insert_parts
led = Led.new
led.opx = 21
led.nedx = 0
led.opy = 55
led.nedy = 0
led.del = HBen.new
self.led["hben"] = led

led = Led.new
led.opx = 0
led.nedx = 3
led.opy = 56
led.nedy = 0
led.del = VBen.new
self.led["vben"] = led

led = Led.new
led.opx = 32
led.nedx = 0
led.opy = 0
led.nedy = 1
led.del = HArm.new
self.led["harm"] = led

led = Led.new
led.opx = 0
led.nedx = 12
led.opy = 0
led.nedy = 6
led.del = VArm.new
self.led["varm"] = led

led = Led.new
led.opx = 0
led.nedx = 2
led.opy = 0
led.nedy = 29
led.del = Hoved.new
self.led["Hoved"] = led

		@flyt_start = true
	end
	
	def FlytAbsolut(x, y)
		@vx = (x - self.x)
		@vy = (y - self.y)
		@len = Math.sqrt(@vx * @vx + @vy * @vy)
		
		@vy /= @len
		@vx /= @len

		self.x += @vx.round
		self.y += @vy.round
		self.move
		(self.x == x && self.y == y)
	end

	def Flyt(x, y)
		if(@flyt_start)
			@flyt_x = @x + x
			@flyt_y = @y + y
			@flyt_start = false
		end
		faerdig = FlytAbsolut(@flyt_x, @flyt_y)
		if(faerdig)
			@flyt_start = true
		end
		faerdig
	end
=begin
=end
end

$Pause_running = false

def Pause(tid)
#	def self.vent(tid)
	if($Pause_running)
		@@timer-=1;
		if(@@timer <= 1)
			$Pause_running = false
		end
	else
		@@timer = tid
		$Pause_running = true
	end
	!$Pause_running
#	end
end


=begin
class Samler
	attr_reader :figurer
	attr_writer :figurer
	def initialize
		@figurer = Array.new
	end
	def +(figur)
		samler = Samler.new()
		samler.figurer << self.figurer
		if(figur.kind_of? Figur)
			samler.figurer << figur
		elsif (figur.kind_of? Samler)
			samler.figurer << figur.figurer
		end
		samler
	end
end

Under Figur
	def initialize
		$model.nyFigur(self)
	end
	def +(figur)
		samler = Samler.new()
		samler.figurer << self
		if(figur.kind_of? Figur)
			samler.figurer << figur
		elsif (figur.kind_of? Samler)
			samler.figurer << figur.figurer
		end
		samler
	end
=end
